#pragma once

#include <string>
#include "../Headers/types.h"
#include "ns.rpc.h"
#define IPLENGTH (4)

//	Server types
struct Server {
	enum Enum {
		Authentication		= 1,
		Authorization 		= 2,
		UserStorage				= 3,
		UserManagement		= 4,
		Email							= 5,
		FileSharing				= 6,
		Calendar					= 7,
		ToDo							= 8,
		Directory					= 9,
		Time							= 10,
		WebServer					= 11,
    Chat              = 12
	};
	typedef enum Enum Type;
};

namespace TOB {
	class Nameserver {
	 private:
		CLIENT *clnt;
		bool connected;

	 public:
		typedef uint32 IP;

		/**
		 *	Constructor - connects to nameserver
		 *
		 *	@param host Host of nameserver
		 */
		Nameserver(std::string host);

		/**
		 *	Destructor - disconnects from nameserver
		 */
		~Nameserver();

    /**
     *  Check if client is connected
     *  
     *  @return Status
     */
    bool isConnected();

		/**
		 *	Request ip from server
		 *
		 *	@param sever Server id (Server::Type)
		 *	@param ipAddr Response
		 *	@return Action result
		 */
		Code::Type requestAddress(Server::Type server, IP &ipAddr);

		/**
		 *	Convert 4-byte ip to string
		 *
		 *	@param ipAddr Source IP
		 *	@param output Output string
		 *	@return Action result
		 */
		static Code::Type convertIP(IP ipAddr, std::string &output);

		/**
		 *	Convert string to 4-byte ip
		 *
		 *	@param input Input string
		 *	@param ipAddr Source IP
		 *	@return Action result
		 */
		static Code::Type convertString(std::string &input, IP &ipAddr);
	};
}
